package summoning2;

import impsoft.bots.reflection.PhysicalObject;
import impsoft.scripting.ibot.structs.AryanTile;

import java.util.Arrays;

import base.DreamScript;
import base.DreamUtility;
import bergCoder.ClosestTile;

public class ObeliskFinder extends DreamUtility {
	public static final int[] obeliskIds = { 29938, 29939, 29943, 29944, 29945, 29951, 29952, 29953, 29954, 29957,
			29959, 29992 };// TODO: validate

	// ids

	public ObeliskFinder(DreamScript cs) {
		super(cs);
	}

	public PhysicalObject getObeliskObject() {
		return cs.getObjectFinder().getPhysicalObject(obeliskIds, cs.getLocation(), false, 17, false);
	}

	public boolean isObeliskNear() {
		return getObeliskObject() != null;
	}

	public Obelisk getNearestObelisk() {
		AryanTile closest = getClosestObeliskLocation();
		for (Obelisk obelisk : Obelisk.values()) {
			if (obelisk.getLocation().equals(closest)) {
				return obelisk;
			}
		}

		return null;
	}

	public AryanTile getClosestObeliskLocation() {
		AryanTile[] summoningObeliskLocs = Obelisk.getSummoningLocations();
		Arrays.sort(summoningObeliskLocs, new ClosestTile(cs));
		return summoningObeliskLocs[0];
	}
}
